class Thing < ActiveRecord::Base
  #To support chinese index
  GENERIC_ANALYSIS_REGEX = /([a-zA-Z]|[\xc0-\xdf][\x80-\xbf])+|[0-9]+|[\xe0-\xef][\x80-\xbf][\x80-\xbf]/
  GENERIC_ANALYZER = Ferret::Analysis::RegExpAnalyzer.new(GENERIC_ANALYSIS_REGEX, true)
  acts_as_ferret({:fields => [ :title, :tags_with_spaces ] }, { :analyzer => GENERIC_ANALYZER })
  #To support taggable
  acts_as_taggable

  acts_as_commentable
  #  has_and_belongs_to_many :users
  has_many :thingsusers,:dependent =>:destroy
  has_many :users,  :through => :thingsusers

  # delimitor
  def tags_with_spaces
    return self.tag_names.join(" ")
  end

  # define the display order by the user count
  def <=>(other)
    self.user_count <=> other.user_count
  end
end
